﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GestionEducativa.Models;

namespace GestionEducativa.DataLayer
{
    public class AlumnoRepository
    {
        Gestion_EducativaEntities ObjectContext = new Gestion_EducativaEntities();

     
        public void InsertarAlumno(Alumnos a)
        {
            ObjectContext.AddToAlumnos(a);
            ObjectContext.SaveChanges();    
        }

        public void BorrarAlumno(string mat)
        {
            Alumnos a = (from al in ObjectContext.Alumnos where al.matricula == mat select al).First();
            ObjectContext.Alumnos.DeleteObject(a);
            ObjectContext.SaveChanges();
        }

        public void ActualizarAlumno(Alumnos al)
        {
           Alumnos  a = ObjectContext.Alumnos.First(ax => ax.matricula == al.matricula);

           a.nombre = al.nombre;
           a.apellidos = al.apellidos;
           a.direccion = al.direccion;
           a.direccion = al.direccion;
           a.correo = al.correo;
           a.estado = al.estado;

           ObjectContext.SaveChanges();
        }

        public IEnumerable<Alumnos> TraerTodosLosAlumnos()
        {
            IEnumerable<Alumnos> ListaAlumnos = (from a in ObjectContext.Alumnos select a).AsEnumerable();

            return ListaAlumnos;
        }

        public Alumnos TraerAlumno(string mat)
        {  
            Alumnos a = (from al in ObjectContext.Alumnos where al.matricula == mat select al).First();

            return a;
        }

        public void HabilitacionAlumno(string mat)
        {
            Alumnos a = (from almn in ObjectContext.Alumnos where almn.matricula == mat select almn).First();
            if (a.estado == true)
            { a.estado = false;  }

            else 
            { a.estado = true; }

            ObjectContext.SaveChanges();
           
        }

    }
}